package com.tuanda.app.customviewdemo.paint;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import com.tuanda.app.customviewdemo.BaseCustomView;
import com.tuanda.app.customviewdemo.R;

/**
 * Created by LiDongduo on 2018/9/21.
 */
public class PaintColorFilterView extends BaseCustomView {
    public PaintColorFilterView(Context context) {
        super(context);
    }

    public PaintColorFilterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PaintColorFilterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_batman_logo);
        canvas.drawBitmap(logoBitmap,50,50,mPaint);
        mPaint.setColorFilter(new LightingColorFilter(0xffffff, 0x008000));
        canvas.drawBitmap(logoBitmap, 50, 120, mPaint);

        mPaint.setColorFilter(new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP));
        canvas.drawBitmap(logoBitmap,50,200,mPaint);

        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(10);
        mPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        canvas.drawBitmap(logoBitmap,50,280,mPaint);
    }
}
